import Vue from 'vue'
import Router from 'vue-router'
import store from '@/vuex/index'

const Seat = r => require.ensure([], () => r(require('@/components/Subscribe/Seat')), 'Seat')
const ConfirmSeat = r => require.ensure([], () => r(require('@/components/Subscribe/ConfirmSeat')), 'Seat')

const Order = r => require.ensure([], () => r(require('@/components/Order/Order')), 'Order')
const OrderStart = r => require.ensure([], () => r(require('@/components/Order/OrderStart')), 'Order')
const OrderStarting = r => require.ensure([], () => r(require('@/components/Order/OrderStarting')), 'Order')
const PayingBill = r => require.ensure([], () => r(require('@/components/Order/PayingBill')), 'Order')

const Mine = r => require.ensure([], () => r(require('@/components/Mine/Mine')), 'Mine')
const UserInfo = r => require.ensure([], () => r(require('@/components/Mine/UserInfo')), 'Mine')
const BindPhone = r => require.ensure([], () => r(require('@/components/Mine/BindPhone')), 'Mine')
const Recharge = r => require.ensure([], () => r(require('@/components/Mine/Recharge')), 'Mine')
const RechargeType = r => require.ensure([], () => r(require('@/components/Mine/RechargeType')), 'Mine')
const SeatRecord = r => require.ensure([], () => r(require('@/components/Mine/SeatRecord')), 'Mine')
const Message = r => require.ensure([], () => r(require('@/components/Mine/Message')), 'Mine')
const ContactUs = r => require.ensure([], () => r(require('@/components/Mine/ContactUs')), 'Mine')
const Coupon = r => require.ensure([], () => r(require('@/components/Mine/Coupon')), 'Mine')
const SureRecharge = r => require.ensure([], () => r(require('@/components/Mine/SureRecharge')), 'Mine')
const PayMode = r => require.ensure([], () => r(require('@/components/Mine/PayMode')), 'Mine')
const PayResult = r => require.ensure([], () => r(require('@/components/Mine/PayResult')), 'Mine')
const MessageDetail = r => require.ensure([], () => r(require('@/components/Mine/MessageDetail')), 'Mine')
const PayDetail = r => require.ensure([], () => r(require('@/components/Mine/PayDetail')), 'Mine')
const BindTel = r => require.ensure([], () => r(require('@/components/Mine/BindTel')), 'Mine')
const MoneyDetail = r => require.ensure([], () => r(require('@/components/Mine/MoneyDetail')), 'Mine')

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '*',
      redirect: 'Seat'
    },
    // 预约订座 Tab
    {
      path: '/Seat',//预约订座
      name: 'Seat',
      component: Seat
    },
    {
      path: '/Seat/ConfirmSeat',//确认订座
      name: 'ConfirmSeat',
      component: ConfirmSeat
    },
    //订单 Tab
    {
      path: '/Order',//订单
      name: 'Order',
      component: Order
    },
    {
      path: '/Order/OrderStart',//订单列表
      name: 'OrderStart',
      component: OrderStart,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Order/OrderStarting',//开始计时
      name: 'OrderStarting',
      component: OrderStarting,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Order/PayingBill',//结账页面
      name: 'PayingBill',
      component: PayingBill,
      meta: {
        can_back: false
      }
    },
    //我的 Tab
    {
      path: '/Mine',//我的
      name: 'Mine',
      component: Mine
    },
    {
      path: '/Mine/UserInfo',//用户信息
      name: 'UserInfo',
      component: UserInfo,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/BindPhone',//绑定手机
      name: 'BindPhone',
      component: BindPhone,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/BindTel',//修改手机
      name: 'BindTel',
      component: BindTel,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/Recharge',//书吧选择
      name: 'Recharge',
      component: Recharge,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/RechargeType',//付款选择
      name: 'RechargeType',
      component: RechargeType,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/SeatRecord',//订座记录
      name: 'SeatRecord',
      component: SeatRecord,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/Message',//消息记录
      name: 'Message',
      component: Message,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/ContactUs',//消息记录
      name: 'ContactUs',
      component: ContactUs,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/Coupon',//我的卡券
      name: 'Coupon',
      component: Coupon,
      meta: {
        can_back: true
      }
    },
    {
      path: '/Mine/SureRecharge',//订单确认
      name: 'SureRecharge',
      component: SureRecharge,
      meta: {
        can_back: true
      }
    }, {
      path: '/Mine/PayDetail',//充值明细
      name: 'PayDetail',
      component: PayDetail,
      meta: {
        can_back: true
      }
    }, {
      path: '/Mine/PayResult',//订单确认
      name: 'PayResult',
      component: PayResult,
      meta: {
        can_back: true
      }
    }, {
      path: '/Mine/MessageDetail',//消息详情
      name: 'MessageDetail',
      component: MessageDetail,
      meta: {
        can_back: true
      }
    }, {
      path: '/PayMode',//支付选择
      name: 'PayMode',
      component: PayMode,
      meta: {
        can_back: true
      }
    }, {
      path: '/Mine/MoneyDetail',
      name: 'MoneyDetail',
      component: MoneyDetail,
      meta: {
        can_back: true
      }

    }
  ]
})

router.beforeEach(function (to, from, next) {
  store.commit('updateLoadingStatus', {isLoading: true})
  next()
})

router.afterEach(function (to) {
  setTimeout(() => {
    store.commit('updateLoadingStatus', {isLoading: false})
  }, 300)
})

export default router
